package com.jvbc.xoso.arrayadapter;

import java.util.ArrayList;

import com.jvbc.xoso.R;
import com.jvbc.xoso.bean.DanhMuc;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class DanhMucArrayAdapter extends ArrayAdapter<DanhMuc>{
	Context context;
	int layoutResourceId;
	ArrayList<DanhMuc> data = new ArrayList<DanhMuc>();
	public DanhMucArrayAdapter(Context context,  int layoutResourceId, ArrayList<DanhMuc> data) {
		super(context, layoutResourceId, data);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.data = data;
	}
	//Lay ra vi tri id cua list
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ImageHolder holder = null;
		if(row == null)
		{
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);
			holder = new ImageHolder();
			holder.txtCategoryName = (TextView)row.findViewById(R.id.txtCategoryName);
			row.setTag(holder);
		}
		else
		{
			holder = (ImageHolder)row.getTag();
		}
		DanhMuc danhmuc = data.get(position);
		holder.txtCategoryName.setText(danhmuc.getMuc());
		return row;
	}
	
	static class ImageHolder
	{
		TextView txtCategoryName;
	}
}